//返回时间戳 入参为时间字符串或为空
const getTimestamp = (dateString) => {
    let d = dateString ? new Date(dateString) : new Date()
    return d.getTime()
}


//返回秒后过期
function getTimestampAfterSeconds(seconds = 10) {
    return Date.now() + seconds * 1000
}

//判断该时间戳是否过期 false 不过期 true 过期
function isTimestampExpired(timestamp) {
    const date = new Date(timestamp)
    const currentDate = new Date()
    return date < currentDate
}

//返回时间格式
function formatTime(){
    const date = new Date();
    const formattedDate = date.toISOString().replace('T', ' ').replace(/\..+/, '');
    return formattedDate
}

module.exports = {
    getTimestamp,
    getTimestampAfterSeconds,
    isTimestampExpired,
    formatTime
}